package com.itheima.时间日期类.JDK8date.计算两个时间间隔Duration;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;

//计算两个时间的间隔
public class JDK8DateDemo9 {

    public static void main(String[] args) {
        LocalDate ld1 = LocalDate.of(2020, 1, 1);
        LocalDate ld2 = LocalDate.of(2047, 12, 24);

        Period per = Period.between(ld1, ld2);
        System.out.println(per);//P27Y11M23D


        System.out.println("-=-=-=-=-=-=-");
        System.out.println("间隔"+per.getYears()+"年");
        System.out.println("间隔"+per.getMonths()+"月");
        System.out.println("间隔"+per.getDays()+"日");
        //public long toTotalMonths()获取此期间的总月数
        System.out.println("共月数"+per.toTotalMonths());

    }
}
